//stop信息管理
var $STOPInformationManagement = {
    DealUrl: function (vueApp, url, type, param) {
        var my = vueApp;
        switch (url) {
            ////删除
            case '/api/STOPInformationManagement/DeleteMuti':
                Mock.mock(host + url, type, function (options) {
                    var delIDs = options.body;
                    var temp = [];
                    for (var i = 0; i < $STOPInformationManagement.EquipmenFacilities.length; i++) {
                        temp.push($STOPInformationManagement.EquipmenFacilities[i]);
                    }
                    for (var i = 0; i < temp.length; i++) {
                        if (delIDs.includes(temp[i].id)) {
                            $STOPInformationManagement.EquipmenFacilities.splice(temp[i], 1);
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //获取List数据
            case '/api/STOPInformationManagement/GetList':
                Mock.mock(host + url, type,
                    function (options) {
                        if ($STOPInformationManagement.EquipmenFacilities.length == 0) {
                            $STOPInformationManagement.InitArray();
                        }
                        var p = JSON.parse(options.body);
                        //条件
                        var observePeople = p.model.observePeople;
                        var observation = p.model.observation;
                        var situation = p.model.situation;
                        var department = p.model.department;
                        var shifts = p.model.shifts;
                        var situation = p.model.situation;
                        var evaluation = p.model.evaluation;
                        var observaDateStart = p.model.observaDateStart;
                        var observaDateEnd = p.model.observaDateEnd;

                        //分页
                        var offset = p.offset;
                        var limit = p.limit;
                        var limitUsers2 = [];
                        for (var i = 0; i < $STOPInformationManagement.EquipmenFacilities.length; i++) {
                            var user = $STOPInformationManagement.EquipmenFacilities[i];
                            if (observePeople && user.observePeople.indexOf(observePeople) == -1)
                                continue;
                            if (observation && user.observation.indexOf(observation) == -1)
                                continue;
                            if (situation && user.situation.indexOf(situation) == -1)
                                continue;
                            if (department && user.department.indexOf(department) == -1)
                                continue;
                            if (shifts && user.shifts.indexOf(shifts) == -1)
                                continue;
                            if (situation && user.situation.indexOf(situation) == -1)
                                continue;
                            if (evaluation && user.evaluation.indexOf(evaluation) == -1)
                                continue;
                            if (observaDateStart && observaDateStart >= user.observaDate)
                                continue;
                            if (observaDateEnd && observaDateEnd <= user.observaDate)
                                continue;

                            user.department = getDicValue("08", user.department) == '' ? user.department : getDicValue("08", user.department);
                            user.situation = getDicValue("14", user.situation) == '' ? user.situation : getDicValue("14", user.situation);

                            limitUsers2.push(user);
                        }

                        var limitUsers = [];
                        for (var i = 0; i < limitUsers2.length; i++) {
                            if (i < offset + limit && i >= offset) {
                                limitUsers.push(limitUsers2[i]);
                            }
                        }
                        return {
                            result: "Success",
                            message: null,
                            data: {
                                pageData: limitUsers,
                                rowCount: limitUsers2.length
                            }
                        };
                    });
                break;
                //获取Input数据
            case '/api/STOPInformationManagement/get':
                Mock.mock(host + url + '?' + param, type, function (options) {

                    var myUsers = parent.$STOPInformationManagement.EquipmenFacilities;
                    myuser = {};
                    var bool = true;
                    for (var i = 0; i < myUsers.length; i++) {
                        if (myUsers[i].id == vueApp.id) {
                            myuser = myUsers[i];
                            bool = false
                            break;
                        }
                    }
                    //新增
                    if (bool) {
                        // myuser.shifts = Mock.mock('@natural()');
                        myuser.shifts = []; //秩序标准
                        myuser.standard = []; //秩序标准
                        myuser.response = []; //人员反应
                        myuser.inspect = []; //个人防护装备从头到脚检查
                        myuser.Causes = []; //人员的位置伤害的原因
                        myuser.program = []; //程序
                        myuser.tool = []; //"工具及设备
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: myuser
                    };
                });
                break;
                ////提交
            case '/api/STOPInformationManagement/Save':
                Mock.mock(host + url, type, function (options) {
                    var thisuser = JSON.parse(options.body);
                    var thisUsers = parent.$STOPInformationManagement.EquipmenFacilities;
                    var cz = true;
                    for (var i = 0; i < thisUsers.length; i++) {
                        if (thisUsers[i].id == thisuser.id) {
                            thisUsers[i].department = thisuser.department;
                            thisUsers[i].shifts = thisuser.shifts;
                            thisUsers[i].observation = thisuser.observation;
                            thisUsers[i].observePeople = thisuser.observePeople;
                            thisUsers[i].observaDate = thisuser.observaDate;
                            thisUsers[i].situation = thisuser.situation;
                            thisUsers[i].evaluation = thisuser.evaluation;
                            thisUsers[i].standard = thisuser.standard;
                            thisUsers[i].response = thisuser.response;
                            thisUsers[i].inspect = thisuser.inspect;
                            thisUsers[i].Causes = thisuser.Causes;
                            thisUsers[i].program = thisuser.program;
                            thisUsers[i].tool = thisuser.tool;
                            cz = false;
                            break;
                        }
                    }
                    if (cz) {
                        //Input 页面需要 去操作List页面的数组 parent
                        parent.$STOPInformationManagement.EquipmenFacilities.push({
                            id: Mock.Random.id(),
                            department: thisuser.department,
                            shifts: thisuser.shifts,
                            observation: '2019-08-20',
                            observePeople: thisuser.observePeople,
                            observaDate: '2019-08-20',
                            situation: thisuser.situation,
                            evaluation: thisuser.evaluation,
                            contractor: thisuser.contractor,
                            standard: thisuser.standard,
                            response: thisuser.response,
                            inspect: thisuser.inspect,
                            Causes: thisuser.Causes,
                            program: thisuser.program,
                            tool: thisuser.tool,
                        });
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
        }
    },
    EquipmenFacilities: [],
    InitArray: function () {
        for (var i = 0; i < 30; i++) {
            $STOPInformationManagement.EquipmenFacilities.push(Mock.mock({
                id: Mock.Random.id(),
                observePeople: Mock.Random.cname(), //观察人
                observation: Mock.mock({
                    "number|10-100": 100
                  }).number, //观察时间
                shifts: randomValue('n68'), //班次
                department: randomValue('n69'), //部门
                situation: randomValue('n69'), //区域
                observaDate: Mock.Random.datetime(), //观察日期
                evaluation: randomValue('50'), //是否安全
                standard: [{
                    standardMain: randomValue("n83")
                }], //秩序标准
                response: [{
                    responseMain: randomValue("n78")
                }], //人员反应
                inspect: [{
                    inspectMain: randomValue("n79")
                }], //个人防护装备从头到脚检查
                Causes: [{
                    CausesMain: randomValue("n80")
                }], //人员的位置伤害的原因
                program: [{
                    programMain: randomValue("n82")
                }], //程序
                tool: [{
                    toolMain: randomValue("n81")
                }], //"工具及设备
                correct: randomValue("92"), //观察到的不安全行为；立即采取的纠正措施；预防再次发生采取的措施
                encourage: randomValue("19"), //观察到的安全行为；为鼓励持续的安全表现所采取的行动
            }));
        }
    }
}



//行为安全观察与沟通频次管理
var $BehaviorSafetyCommunicationFrequency = {
    DealUrl: function (vueApp, url, type, param) {
        var my = vueApp;
        switch (url) {
            //删除
            case '/api/BehaviorSafetyCommunicationFrequency/DeleteMuti':
                Mock.mock(host + url, type, function (options) {
                    var delIDs = options.body;
                    var temp = [];
                    for (var i = 0; i < $BehaviorSafetyCommunicationFrequency.List.length; i++) {
                        temp.push($BehaviorSafetyCommunicationFrequency.List[i]);
                    }
                    for (var i = 0; i < temp.length; i++) {

                        if (delIDs.includes(temp[i].id)) {
                            $BehaviorSafetyCommunicationFrequency.List.splice(temp[i], 1);
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //获取List数据
            case '/api/BehaviorSafetyCommunicationFrequency/GetList':
                Mock.mock(host + url, type,
                    function (options) {
                        if ($BehaviorSafetyCommunicationFrequency.List.length == 0) {
                            $BehaviorSafetyCommunicationFrequency.InitArray();
                        }
                        var p = JSON.parse(options.body);
                        //条件
                        var department = p.model.department;
                        var Objective = p.model.Objective;
                        var PersonInCharge = p.model.PersonInCharge;
                        var Participant = p.model.Participant;
                        var name = p.model.name;
                        //分页
                        var offset = p.offset;
                        var limit = p.limit;
                        var limitUsers2 = [];
                        for (var i = 0; i < $BehaviorSafetyCommunicationFrequency.List.length; i++) {
                            var user = $BehaviorSafetyCommunicationFrequency.List[i];

                            if (department && user.department.indexOf(department) == -1)
                                continue;
                            if (Objective && user.Objective.indexOf(Objective) == -1)
                                continue;
                            if (PersonInCharge && user.PersonInCharge.indexOf(PersonInCharge) == -1)
                                continue;
                            if (Participant && user.Participant.indexOf(Participant) == -1)
                                continue;
                            if (name && user.name.indexOf(name) == -1)
                                continue;
                            //user.Database = getDicValue("300", user.Database) == '' ? user.Database : getDicValue("300", user.Database);
                            limitUsers2.push(user);
                        }

                        var limitUsers = [];
                        for (var i = 0; i < limitUsers2.length; i++) {
                            if (i < offset + limit && i >= offset) {
                                limitUsers.push(limitUsers2[i]);
                            }
                        }
                        return {
                            result: "Success",
                            message: null,
                            data: {
                                pageData: limitUsers,
                                rowCount: limitUsers2.length
                            }
                        };
                    });
                break;
                //获取Input数据
            case '/api/BehaviorSafetyCommunicationFrequency/get':
                Mock.mock(host + url + '?' + param, type, function (options) {
                    var myUsers = parent.$BehaviorSafetyCommunicationFrequency.List;
                    myuser = {};
                    for (var i = 0; i < myUsers.length; i++) {
                        if (myUsers[i].id == vueApp.id) {
                            myuser = myUsers[i];
                            break;
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: myuser
                    };
                });
                break;
                //提交
            case '/api/BehaviorSafetyCommunicationFrequency/Save':
                Mock.mock(host + url, type, function (options) {
                    var thisuser = JSON.parse(options.body);
                    var thisUsers = parent.$BehaviorSafetyCommunicationFrequency.List;
                    var cz = true;
                    for (var i = 0; i < thisUsers.length; i++) {
                        if (thisUsers[i].id == thisuser.id) {
                            thisUsers[i].department = thisuser.department;
                            thisUsers[i].Objective = thisuser.Objective;
                            thisUsers[i].PersonInCharge = thisuser.PersonInCharge;
                            thisUsers[i].Participant = thisuser.Participant;
                            thisUsers[i].name = thisuser.name;
                            thisUsers[i].position = thisuser.position;
                            thisUsers[i].StandardType = thisuser.StandardType;
                            thisUsers[i].InvestigationPost = thisuser.InvestigationPost;
                            thisUsers[i].Remark = thisuser.Remark;
                            cz = false;
                            break;
                        }
                    }
                    if (cz) {
                        //Input 页面需要 去操作List页面的数组 parent
                        parent.$BehaviorSafetyCommunicationFrequency.List.unshift({
                            id: Mock.Random.id(),
                            department: thisuser.department,
                            Objective: thisuser.Objective,
                            PersonInCharge: thisuser.PersonInCharge,
                            Participant: thisuser.Participant,
                            name: thisuser.name,
                            position: thisuser.position,
                            Frequency: thisuser.Frequency,
                            StandardType: thisuser.StandardType,
                            InvestigationPost: thisuser.InvestigationPost,
                            Remark: thisuser.Remark,
                            FrequencyText: $BehaviorSafetyCommunicationFrequency.ShowFrequencyText(Frequency.Type, Frequency.MoveUp, Frequency.Text)
                        });
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //获取设置频次数据
            case '/api/BehaviorSafetyCommunicationFrequency/getfrequency':
                Mock.mock(host + url + '?' + param, type, function (options) {
                    var myUsers = parent.parent.$BehaviorSafetyCommunicationFrequency.List;
                    myuser = {};
                    for (var i = 0; i < myUsers.length; i++) {
                        if (myUsers[i].id == vueApp.id) {
                            myuser = myUsers[i];
                            break;
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: myuser
                    };
                });
                break;
                //提交设置频次
            case '/api/BehaviorSafetyCommunicationFrequency/SaveSetFrequency':
                Mock.mock(host + url, type, function (options) {
                    var thisuser = JSON.parse(options.body);
                    var thisUsers = parent.parent.$BehaviorSafetyCommunicationFrequency.List;
                    //console.log(1)
                    //console.log(options)
                    //console.log(1)
                    for (var i = 0; i < thisUsers.length; i++) {
                        if (thisUsers[i].id == thisuser.id) {
                            thisUsers[i].Frequency = thisuser.Frequency;
                            thisUsers[i].FrequencyText = $BehaviorSafetyCommunicationFrequency.ShowFrequencyText(thisuser.Frequency.Type, thisuser.Frequency.MoveUp, thisuser.Frequency.Text)
                            break;
                        }
                    }
                    //parent.myuser.FrequencyText = "123123";
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //删除input内table
            case '/api/BehaviorSafetyCommunicationFrequency/DeleteInputTable':
                Mock.mock(host + url, type, function (options) {
                    var delIDs = JSON.parse(options.body); //要删除的id数组

                    if (delIDs.length > 1) {
                        var tempdelIDs = [];
                        for (var i = 0; i < delIDs.length; i++) {
                            if (tempdelIDs.indexOf(delIDs[i]) == -1) {
                                tempdelIDs.push(delIDs[i]);
                            }
                        }
                        delIDs = tempdelIDs;
                    }
                    console.log(delIDs);

                    var list = parent.$BehaviorSafetyCommunicationFrequency.List; //原数据
                    var temp = []; //临时数据组
                    for (var i = 0; i < list.length; i++) {
                        temp.push(list[i]);
                    }
                    //声明被删除对象的索引及数量数组{index:,count:}
                    var delTeam = [];
                    var index = -1; //删除索引默认值
                    var count = 0; //删除数量默认值
                    var listIndex = -1;
                    //遍历传过来的需要被删除的id集合
                    for (var k = 0; k < delIDs.length; k++) {
                        //遍历临时数据组
                        for (var i = 0; i < temp.length; i++) {
                            //遍历临时数据组中的InputTable对象中的数据
                            for (var j = 0; j < temp[i].InputTable.length; j++) {
                                if (delIDs[k] === temp[i].InputTable[j].id) {
                                    listIndex = i;
                                    if (count === 0) {
                                        index = j;
                                        count++;
                                    } else {
                                        if (temp[i].InputTable[j].id === temp[i].InputTable[j - 1].id) count++;
                                    }
                                }
                            }
                        }
                        if (index > -1) {
                            delTeam.push({
                                'index': index,
                                'count': count,
                                'listIndex': listIndex
                            });
                            count = 0;
                            index = -1;
                        }
                    }
                    for (var i = delTeam.length - 1; i >= 0; i--) {
                        console.log(delTeam[i])
                        parent.$BehaviorSafetyCommunicationFrequency.List[delTeam[i].listIndex].InputTable.splice(delTeam[i].index, delTeam[i].count);
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //获取Input数据
            case '/api/BehaviorSafetyCommunicationFrequency/getInputTable':
                Mock.mock(host + url + '?' + param, type, function (options) {
                    var myUsers = parent.parent.$BehaviorSafetyCommunicationFrequency.List;
                    myuser = [];
                    for (var i = 0; i < myUsers.length; i++) {

                        for (var j = 0; j < myUsers[i].InputTable.length; j++) {
                            if (myUsers[i].InputTable[j].id == vueApp.id) {
                                myuser.push(myUsers[i].InputTable[j]);
                            }
                        }

                    }
                    var _myuser = {};
                    if (myuser.length > 0) {
                        myuser.forEach(function (v, i) {
                            if (i == 0) {
                                for (var key in v) {
                                    _myuser[key] = v[key];
                                }
                                _myuser.Standard = [];
                                _myuser.Standard.push(v.Standard);
                            } else {
                                _myuser.Standard.push(v.Standard);
                            }
                        })
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: _myuser
                    };
                });
                break;
                //提交Input数据
            case '/api/BehaviorSafetyCommunicationFrequency/SaveInputTable':
                Mock.mock(host + url, type, function (options) {
                    var thisuser = JSON.parse(options.body);
                    var thisUsers = parent.parent.$BehaviorSafetyCommunicationFrequency.List;
                    if (thisuser.id) {
                        var InputTableIndex = [];
                        for (var i = 0; i < thisUsers.length; i++) {
                            if (thisUsers[i].id == my.pid) {
                                for (var j = 0; j < thisUsers[i].InputTable.length; j++) {
                                    if (thisUsers[i].InputTable[j].id == thisuser.id) {
                                        InputTableIndex.push(j);
                                    }
                                }
                                for (var k = InputTableIndex.length - 1; k >= 0; k--) {
                                    thisUsers[i].InputTable.splice(InputTableIndex[k], 1);
                                }
                                for (var l = thisuser.Standard.length - 1; l >= 0; l--) {
                                    var data = {
                                        id: thisuser.id,
                                        Project: thisuser.Project, //排查项目
                                        Region: thisuser.Region, //涉及区域
                                        Remark: thisuser.Remark, //备注说明
                                        Standard: thisuser.Standard[l], //排查标准
                                        RiskLevel: thisuser.RiskLevel
                                    }
                                    thisUsers[i].InputTable.splice(InputTableIndex[0], 0, data);
                                }
                                break;
                            }

                        }
                    } else {
                        for (var i = 0; i < thisUsers.length; i++) {
                            if (thisUsers[i].id == my.pid) {
                                var id = Mock.Random.id();
                                for (var j = thisuser.Standard.length - 1; j >= 0; j--) {
                                    thisUsers[i].InputTable.unshift({
                                        id: id,
                                        Project: thisuser.Project, //排查项目
                                        Region: thisuser.Region, //涉及区域
                                        Remark: thisuser.Remark, //备注说明
                                        Standard: thisuser.Standard[j], //排查标准
                                        RiskLevel: randomKey("03") //隐患级别
                                    })
                                }

                            }
                        }
                    }

                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //提交手动录入隐患排查标准方式
            case '/api/BehaviorSafetyCommunicationFrequency/SaveInputStandard':
                Mock.mock(host + url, type, function (options) {
                    var thisuser = JSON.parse(options.body);
                    var thisUsers = parent.parent.parent.$BehaviorSafetyCommunicationFrequency.List;
                    for (var i = 0; i < thisUsers.length; i++) {
                        if (thisUsers[i].id == thisuser.pid) {
                            for (var j = 0; j < thisUsers[i].InputTable.length; j++) {
                                if (thisUsers[i].InputTable[j].id == thisuser.id) {
                                    thisUsers[i].InputTable.splice(j, 0, {
                                        id: thisuser.id,
                                        Project: thisUsers[i].InputTable[j].Project, //排查项目
                                        Region: thisUsers[i].InputTable[j].Region, //涉及区域
                                        Remark: thisUsers[i].InputTable[j].Remark, //备注说明
                                        Standard: {
                                            name: Mock.Random.id(),
                                            data: thisuser.InputStandard,
                                            type: '' //暂无对应设置，先空缺
                                        }, //排查标准
                                        RiskLevel: randomKey("03") //隐患级别
                                    });
                                    break;
                                }
                            }
                        }
                    }

                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
        }
    },
    List: [],
    InitArray: function () {

        for (var i = 0; i < 80; i++) {
            var PersonInChargePidA = randomTreeNode(PersonInChargeTree, '0', true);
            var PersonInChargePidB = randomTreeNode(PersonInChargeTree, '0', true);
            var PersonInChargeIdA = randomTreeNode(PersonInChargeTree, PersonInChargePidA);
            var PersonInChargeIdB = randomTreeNode(PersonInChargeTree, PersonInChargePidB);

            var Frequency_MoveUp = Math.floor(Math.random() * 10 + 1);
            var Frequency_Type = Cycle[Math.floor(Math.random() * Cycle.length)];
            var Frequency_Text = '2020-05-23 17:00:00';

            //Input页内的table数据
            var StandardList = $BehaviorSafetyCommunicationFrequency.generateData(); //生成排查标准数据
            var InputTable = [];
            for (var k = 0; k < 5; k++) {
                var id = Mock.Random.id()
                var Project = Mock.mock('@csentence(4)');
                var Region = randomTreeNode(myTree, '0', true);
                var Remark = Mock.mock('@csentence(6)');
                var c = 0;
                for (var j = 0; j < Math.random() * 8 + 1; j++) {
                    //随机生成排查标准内容
                    var Standard = StandardList[Math.floor(Math.random() * StandardList.length)];
                    //去重开关
                    var flag = true;
                    InputTable.forEach(function (v, i) {
                        //判断是否已有相同内容的排查标准
                        if (v.Standard.name === Standard.name) {
                            flag = false;
                        }
                    })
                    if (flag) {
                        c++;
                        //加个序号而已
                        Standard.data = c + '.' + Standard.data;
                        InputTable.push(Mock.mock({
                            id: id,
                            Project: Project, //排查项目
                            Region: Region, //涉及区域
                            Remark: Remark, //备注说明
                            //Standard: `${j + 1}.` + Mock.mock('@csentence(6)'),//排查标准
                            Standard: Standard, //排查标准
                            RiskLevel: randomKey("03") //隐患级别
                        }));
                    }

                }

            }
            $BehaviorSafetyCommunicationFrequency.List.push(Mock.mock({
                department: randomValue('15'), //部门
                name: Mock.Random.cname(), //人员姓名
                position: randomValue('n53'), //职务
                id: Mock.Random.id(), //序号
                Frequency: {
                    IsNot: true, //是否提醒
                    Month: randomKey("61"), //月
                    Week: randomKey("63"), //周
                    Day: randomKey("62"), //日
                    Hour: randomKey("64"), //时
                    Text: Frequency_Text, //自定义内容
                    Type: Frequency_Type, //radio选中类型
                    MoveUp: Frequency_MoveUp + '', //天数
                }, //提醒频次
                FrequencyText: $BehaviorSafetyCommunicationFrequency.ShowFrequencyText(Frequency_Type, Frequency_MoveUp, Frequency_Text), //提醒频次结果文本
                InputTable: InputTable
            }));

        }
    },
    //生成FrequencyText
    ShowFrequencyText: function (Frequency_Type, Frequency_MoveUp, Frequency_Text) {
        switch (Frequency_Type) {
            case "Year":
                return "每年执行1次，年底提前" + Frequency_MoveUp + '天提醒';
                break;
            case "Month":
                return "每月执行1次，月底提前" + Frequency_MoveUp + '天提醒';
                break;
            case "HalfYear":
                return "每半年执行1次，提前" + Frequency_MoveUp + '天提醒';
                break;
            case "Quarter":
                return "每季度执行1次，提前" + Frequency_MoveUp + '天提醒';
                break;
            case "TenDay":
                return "每旬执行1次，提前" + Frequency_MoveUp + '天提醒';
                break;
            case "Week":
                return "每周执行1次，提前" + Frequency_MoveUp + '天提醒';
                break;
            case "Customized":
                return "在" + Frequency_Text + "执行1次，提前" + Frequency_MoveUp + '天提醒';
                break;
            case "Day":
                return "每天执行1次，提前" + Frequency_MoveUp + '小时提醒';
                break;
            default:
                break;
        }
    },
    generateData: function () {
        const data = [];
        for (let i = 1; i <= 15; i++) {
            data.push(Mock.mock({
                name: i,
                data: '排查标准${i}',
                type: '6'
            }));
        }
        return data;
    }
}

////生成treeNode随机数,如果b为true则获取父级节点，否则为最底级节点
//var pid = randomTreeNode(RisksTree, '0', true); 获取父id为0（顶级节点），数据集为RisksTree中的节点，并随机返回一条
//var cid = randomTreeNode(RisksTree, pid);获取父id为pid，数据集为RisksTree中的最底级节点，并随机返回一条
//var id  = randomTreeNode(RisksTree);获取数据集为RisksTree中的最底级节点，并随机返回一条
function randomTreeNode(tree, pid, b) {
    var result = '';
    var tempArray = [];
    if (!b) {
        var idArray = [];
        var pidArray = [];
        tree.forEach(function (v, i) {
            if (pid) {
                if (pid == v.pid) {
                    idArray.push(v.id);
                    pidArray.push(v.pid);
                }
            } else {
                idArray.push(v.id);
                pidArray.push(v.pid);
            }
        })
        tempArray = idArray.filter(function (v) {
            return pidArray.indexOf(v) === -1
        });
        result = tempArray[Math.floor(Math.random() * tempArray.length)] + '';
    } else {
        tree.forEach(function (v, i) {
            if (v.pid + '' == '0') {
                tempArray.push(v.id);
            }
        })
        result = tempArray[Math.floor(Math.random() * tempArray.length)] + '';
    }
    return result;
}
//根据tree数据中的id获取对应的name值
function getTreeValue(tree, id) {
    var value = '';
    tree.forEach(function (v, i) {
        if (v.id + '' == id + '') {
            value = v.name;
            return;
        }
    })
    return value;
}
//树型数据扁平化处理
function fnCommon(data, pid) {
    var result = [],
        temp;
    data.forEach(function (v, i) {
        if (v.pid == pid) {
            var obj = {};
            for (var key in v) {
                obj[key] = v[key];
            }
            temp = this.fnCommon(data, data[i].id);
            if (temp.length > 0) {
                obj.children = temp;
            }
            result.push(obj);
        }
    })
    return result
}
//车间
var myTree = [{
        "id": '110',
        "pid": '0',
        "name": "A车间",
    },
    {
        "id": '110001',
        "pid": '110',
        "name": "A车间001",
    },
    {
        "id": '110002',
        "pid": '110',
        "name": "A车间002",
    },
    {
        "id": '111',
        "pid": '0',
        "name": "B车间",
    },
    {
        "id": '111001',
        "pid": '111',
        "name": "B车间001",
    },
    {
        "id": '111002',
        "pid": '111',
        "name": "B车间002",
    }
];

//负责人
var PersonInChargeTree = [{
        "id": 100,
        "pid": 0,
        "name": "总经理"
    },
    {
        "id": 200,
        "pid": 0,
        "name": "生产部"
    },
    {
        "id": 300,
        "pid": 0,
        "name": "技术科"
    },
    {
        "id": 400,
        "pid": 0,
        "name": "工程设备科"
    },
    {
        "id": 100001,
        "pid": 100,
        "name": "张三"
    },
    {
        "id": 100002,
        "pid": 100,
        "name": "李四"
    },
    {
        "id": 200001,
        "pid": 200,
        "name": "胡伟"
    },
    {
        "id": 200002,
        "pid": 200,
        "name": "胡博"
    },
    {
        "id": 300001,
        "pid": 300,
        "name": "李师伯"
    },
    {
        "id": 300002,
        "pid": 300,
        "name": "康师傅"
    },
    {
        "id": 400001,
        "pid": 400,
        "name": "王二"
    },
]
var Cycle = [
    "Year", "Month", "HalfYear", "Quarter", "TenDay", "Week", "Customized", "Day"
]



// 履职职责落实情况管理
var $DutiesAndResponsibilities = {
    DealUrl: function (vueApp, url, type, param) {
        switch (url) {

            //提交_个人评估保存
            case '/api/DutiesAndResponsibilities/GRSBSave':
                Mock.mock(host + url, type, function (options) {
                    var thisentity = JSON.parse(options.body);
                    var thisArrays = parent.$DutiesAndResponsibilities.Arrays;
                    var cz = true;
                    for (var i = 0; i < thisArrays.length; i++) {
                        //按自己实际的去修改内容
                        if (thisArrays[i].id == thisentity.id) {
                            thisArrays[i].years = thisentity.years;
                            thisArrays[i].assessPurpose = thisentity.assessPurpose;
                            thisArrays[i].assessTime = thisentity.assessTime;
                            thisArrays[i].assessContent = thisentity.assessContent;
                            thisArrays[i].assessObj = thisentity.assessObj;
                            thisArrays[i].reviewGroup = thisentity.reviewGroup;
                            thisArrays[i].assessMethod = thisentity.assessMethod;
                            thisArrays[i].employmentLicenseList = thisentity.employmentLicenseList;

                            thisArrays[i].assessResult = thisentity.assessResult;
                            thisArrays[i].selfEvaluation = thisentity.selfEvaluation;
                            thisArrays[i].nextStepImprovementPlan = thisentity.nextStepImprovementPlan;
                            //领导评估用
                            thisArrays[i].overallEvaluation = thisentity.overallEvaluation;
                            thisArrays[i].advantage = thisentity.advantage;
                            thisArrays[i].itemImproved = thisentity.itemImproved;

                            thisArrays[i].tableData = thisentity.tableData; //子表_个人评估表

                            thisArrays[i].reviewOpinion = thisentity.reviewOpinion;//评审意见

                            cz = false;
                            break;
                        }
                    }
                    if (cz) {
                        //Input 页面需要 去操作List页面的数组 parent
                        //按自己实际的去添加内容
                        parent.$DutiesAndResponsibilities.Arrays.push({
                            id: thisentity.id,
                            years: thisentity.years,
                            assessPurpose: thisentity.assessPurpose,
                            assessTime: thisentity.assessTime,
                            assessContent: thisentity.assessContent,
                            assessObj: thisentity.assessObj,
                            reviewGroup: thisentity.reviewGroup,
                            assessMethod: thisentity.assessMethod,
                            //employmentLicenseList: thisuser.employmentLicenseList,
                            assessResult: thisentity.assessResult,
                            selfEvaluation: thisentity.selfEvaluation,
                            nextStepImprovementPlan: thisentity.nextStepImprovementPlan,

                            //领导评估用
                            overallEvaluation : thisentity.overallEvaluation,
                            advantage : thisentity.advantage,
                            itemImproved : thisentity.itemImproved,

                            tableData: thisentity.tableData, //子表_个人评估表

                            reviewOpinion : thisentity.reviewOpinion, //评审意见
                        });
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;

            //提交_履职能力评估计划保存
            case '/api/DutiesAndResponsibilities/SBSave':
                Mock.mock(host + url, type, function (options) {
                    var thisentity = JSON.parse(options.body);
                    var thisArrays = parent.$DutiesAndResponsibilities.Arrays;
                    var cz = true;
                    for (var i = 0; i < thisArrays.length; i++) {
                        //按自己实际的去修改内容
                        if (thisArrays[i].id == thisentity.id) {
                            thisArrays[i].years = thisentity.years;
                            thisArrays[i].assessPurpose = thisentity.assessPurpose;
                            thisArrays[i].assessTime = thisentity.assessTime;
                            thisArrays[i].assessContent = thisentity.assessContent;
                            thisArrays[i].assessObj = thisentity.assessObj;
                            thisArrays[i].reviewGroup = thisentity.reviewGroup;
                            thisArrays[i].assessMethod = thisentity.assessMethod;
                            thisArrays[i].employmentLicenseList = thisentity.employmentLicenseList;
                            thisArrays[i].assessResult = thisentity.assessResult;

                            cz = false;
                            break;
                        }
                    }
                    if (cz) {
                        //Input 页面需要 去操作List页面的数组 parent
                        //按自己实际的去添加内容
                        parent.$DutiesAndResponsibilities.Arrays.push({
                            id: thisentity.id,
                            years: thisentity.years,
                            assessPurpose: thisentity.assessPurpose,
                            assessTime: thisentity.assessTime,
                            assessContent: thisentity.assessContent,
                            assessObj: thisentity.assessObj,
                            reviewGroup: thisentity.reviewGroup,
                            assessMethod: thisentity.assessMethod,
                            //employmentLicenseList: thisuser.employmentLicenseList,
                            assessResult: thisentity.assessResult,
                        });
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;

            //获取List数据
            case '/api/DutiesAndResponsibilities/PGGetList':
                Mock.mock(host + url, type,
                    function (options) {
                        if ($DutiesAndResponsibilities.Arrays.length == 0) {
                            $DutiesAndResponsibilities.InitArray();
                        }
                        var p = JSON.parse(options.body);
                        //查询条件 写自己的查询条件 
                        //var name = p.model.name;
                        var years = p.model.years;
                        var assessObj = p.model.assessObj;

                        //分页条件
                        var offset = p.offset;
                        var limit = p.limit;
                        //查询条件 按自己实际的去过滤
                        var limitArrays2 = [];
                        for (var i = 0; i < $DutiesAndResponsibilities.Arrays.length; i++) {
                            var user = $DutiesAndResponsibilities.Arrays[i];
                            //if (name && user.name.indexOf(name) == -1)
                            //    continue;
                            //年份
                            if (years && user.years.indexOf(years) == -1)
                                continue;
                            //评估对象
                            if (assessObj && user.assessObj.indexOf(assessObj) == -1)
                                continue;

                            limitArrays2.push(user);
                        }
                        var limitArrays = [];
                        for (var i = 0; i < limitArrays2.length; i++) {
                            if (i < offset + limit && i >= offset) {
                                limitArrays.push(limitArrays2[i]);
                            }
                        }
                        return {
                            result: "Success",
                            message: null,
                            data: {
                                pageData: limitArrays,
                                rowCount: limitArrays2.length
                            }
                        };
                    });
                break;

            ////单行删除
            case '/api/DutiesAndResponsibilities/OneDeleteMuti':
                Mock.mock(host + url, type, function (options) {
                    console.log('ufofuo');
                    var delIDs = options.body;
                    var temp = [];
                    for (var i = 0; i < $DutiesAndResponsibilities.Arrays.length; i++) {
                        temp.push($DutiesAndResponsibilities.Arrays[i]);
                    }
                    for (var i = 0; i < temp.length; i++) {
                        if (delIDs.includes(temp[i].id)) {
                            $DutiesAndResponsibilities.Arrays.splice(temp[i], 1);
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
            //提交
            case '/api/DutiesAndResponsibilities/MBSave':
                Mock.mock(host + url, type, function (options) {
                    var thisentity = JSON.parse(options.body);
                    var thisArrays = parent.$DutiesAndResponsibilities.Arrays;
                    var cz = true;
                    for (var i = 0; i < thisArrays.length; i++) {
                        //按自己实际的去修改内容
                        if (thisArrays[i].id == thisentity.id) {
                            thisArrays[i].dutyName = thisentity.dutyName;
                            thisArrays[i].dutyMine = thisentity.dutyMine;
                            thisArrays[i].situation = thisentity.situation;
                            thisArrays[i].date = thisentity.date;
                            thisArrays[i].evaluation = thisentity.evaluation;
                            thisArrays[i].score = thisentity.score;
                            thisArrays[i].name = thisentity.name;
                            thisArrays[i].remarks = thisentity.remarks;
                            //thisArrays[i].classification = thisentity.classification;
                            cz = false;
                            break;
                        }
                    }
                    if (cz) {
                        //Input 页面需要 去操作List页面的数组 parent
                        //按自己实际的去添加内容
                        parent.$DutiesAndResponsibilities.Arrays.unshift({
                            id: thisentity.id,
                            //id: guid(),
                            dutyName: thisentity.dutyName,
                            dutyMine: thisentity.dutyMine,
                            situation: thisentity.situation,
                            date: thisentity.date,
                            evaluation: thisentity.evaluation,
                            score: thisentity.score,
                            name: thisentity.name,
                            remarks: thisentity.remarks,
                            //classification: thisentity.classification,
                        });
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;

            //获取List数据
            case '/api/DutiesAndResponsibilities/GetMBList':
                Mock.mock(host + url, type,
                    function (options) {
                        if ($DutiesAndResponsibilities.Arrays.length == 0) {
                            $DutiesAndResponsibilities.InitArray();
                        }
                        var p = JSON.parse(options.body);
                        //查询条件 写自己的查询条件 
                        var name = p.model.name;

                        //评估类型
                        var classification = getDicValue("w66", p.model.classification);

                        //分页条件
                        var offset = p.offset;
                        var limit = p.limit;
                        //查询条件 按自己实际的去过滤
                        var limitArrays2 = [];
                        for (var i = 0; i < $DutiesAndResponsibilities.Arrays.length; i++) {
                            var user = $DutiesAndResponsibilities.Arrays[i];
                            if (name && user.name.indexOf(name) == -1)
                                continue;
                            //评估类型
                            if (classification && user.classification.indexOf(classification) == -1)
                                continue;
                            user.classification = getDicValue("w66", user.classification) == '' ? user.classification : getDicValue("w66", user.classification);

                            limitArrays2.push(user);
                        }
                        var limitArrays = [];
                        for (var i = 0; i < limitArrays2.length; i++) {
                            if (i < offset + limit && i >= offset) {
                                limitArrays.push(limitArrays2[i]);
                            }
                        }
                        //console.log(limitArrays);
                        return {
                            result: "Success",
                            message: null,
                            data: {
                                pageData: limitArrays,
                                rowCount: limitArrays2.length
                            }
                        };
                    });
                break;


            ////删除
            case '/api/DutiesAndResponsibilities/DeleteMuti':
                Mock.mock(host + url, type, function (options) {
                    var delIDs = options.body;
                    var temp = [];
                    for (var i = 0; i < $DutiesAndResponsibilities.Arrays.length; i++) {
                        temp.push($DutiesAndResponsibilities.Arrays[i]);
                    }
                    for (var i = 0; i < temp.length; i++) {
                        if (delIDs.includes(temp[i].id)) {
                            $DutiesAndResponsibilities.Arrays.splice(temp[i], 1);
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
            //获取List数据
            case '/api/DutiesAndResponsibilities/GetList':
                Mock.mock(host + url, type,
                    function (options) {
                        if ($DutiesAndResponsibilities.Arrays.length == 0) {
                            $DutiesAndResponsibilities.InitArray();
                        }
                        var p = JSON.parse(options.body);
                        //查询条件 写自己的查询条件 
                        var name = p.model.name;
                        //分页条件
                        var offset = p.offset;
                        var limit = p.limit;
                        //查询条件 按自己实际的去过滤
                        var limitArrays2 = [];
                        for (var i = 0; i < $DutiesAndResponsibilities.Arrays.length; i++) {
                            var user = $DutiesAndResponsibilities.Arrays[i];
                            if (name && user.name.indexOf(name) == -1)
                                continue;
                            limitArrays2.push(user);
                        }
                        var limitArrays = [];
                        for (var i = 0; i < limitArrays2.length; i++) {
                            if (i < offset + limit && i >= offset) {
                                limitArrays.push(limitArrays2[i]);
                            }
                        }
                        return {
                            result: "Success",
                            message: null,
                            data: {
                                pageData: limitArrays,
                                rowCount: limitArrays2.length
                            }
                        };
                    });
                break;
                //获取Input数据
            case '/api/DutiesAndResponsibilities/get':
                Mock.mock(host + url + '?' + param, type, function (options) {
                    var myArrays = parent.$DutiesAndResponsibilities.Arrays;
                    myarray = {};
                    for (var i = 0; i < myArrays.length; i++) {
                        if (myArrays[i].id == vueApp.id) {
                            myarray = myArrays[i];
                            break;
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: myarray
                    };
                });
                break;
                //提交
            case '/api/DutiesAndResponsibilities/Save':
                Mock.mock(host + url, type, function (options) {
                    var thisentity = JSON.parse(options.body);
                    var thisArrays = parent.$DutiesAndResponsibilities.Arrays;
                    var cz = true;
                    for (var i = 0; i < thisArrays.length; i++) {
                        //按自己实际的去修改内容
                        if (thisArrays[i].id == thisentity.id) {
                            thisArrays[i].dutyName = thisentity.dutyName;
                            thisArrays[i].dutyMine = thisentity.dutyMine;
                            thisArrays[i].situation = thisentity.situation;
                            thisArrays[i].date = thisentity.date;
                            thisArrays[i].evaluation = thisentity.evaluation;
                            thisArrays[i].score = thisentity.score;
                            thisArrays[i].name = thisentity.name;
                            thisArrays[i].remarks = thisentity.remarks;
                            cz = false;
                            break;
                        }
                    }
                    if (cz) {
                        //Input 页面需要 去操作List页面的数组 parent
                        //按自己实际的去添加内容
                        parent.$DutiesAndResponsibilities.Arrays.push({
                            id: thisentity.id,
                            dutyName: thisentity.dutyName,
                            dutyMine: thisentity.dutyMine,
                            situation: thisentity.situation,
                            date: thisentity.date,
                            evaluation: thisentity.evaluation,
                            score: thisentity.score,
                            name: thisentity.name,
                            remarks: thisentity.remarks,
                        });
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
        }
    },
    Arrays: [],
    InitArray: function () {
        for (var i = 0; i < 20; i++) {
            var PersonInChargePidA = randomTreeNode(PersonInChargeTree, '0', true);
            var PersonInChargePidB = randomTreeNode(PersonInChargeTree, '0', true);
            var PersonInChargeIdA = randomTreeNode(PersonInChargeTree, PersonInChargePidA);
            var PersonInChargeIdB = randomTreeNode(PersonInChargeTree, PersonInChargePidB);

            var tableData = [];
            for (var j = 0; j < 3; j++) {
                tableData.push({
                    postSafeProductionContent: Mock.mock('@cparagraph(1, 3)'), //岗位安全生产责任内容
                    assessmentContent: Mock.mock('@cparagraph(1, 3)'), //考核内容
                    weightScore: Mock.Random.string('number', 2), //权重分
                    effectAndDescription: Mock.mock('@cparagraph(1, 3)'), //评估描述
                    score:"",// Mock.Random.string('number', 2), //评分
                })
            }
            //注意  随机数据初始都是随机姓名，需要自己手动调整
            $DutiesAndResponsibilities.Arrays.push(Mock.mock({
                id: Mock.Random.id(), //必须有
                dutyName: 'XXXXXXXXXXXXX', //履职职责落实情况名称
                dutyMine: randomValue('17'), //履职职责落实情况内容
                situation: randomValue('n54'), //落实情况
                date: Mock.Random.date(), //mock定义的日期
                evaluation: randomValue('n55'), //评价
                // 'score|70-100': 1,
                score: Mock.Random.string('number', 2),
                name: Mock.Random.cname(),
                remarks: Mock.mock('@county(true)'),
                classification: randomValue('w66'), //评估类型
                //履职能力评估计划
                years: Mock.Random.date('yyyy'), //年份
                assessPurpose: randomValue('AssessP1'), //评估目的
                assessContent: randomValue('AssessP2'), //评估内容
                assessObj: randomValue('AssessP3'), //评估对象
                reviewGroup: randomValue('AssessP4'), //评审小组
                assessMethod: randomValue('AssessP5'), //评估方式
                assessTime: Mock.Random.date(), //评估时间
                employmentLicenseList: evaluatorList(), //子表_被评估人
                OverdueScope: [PersonInChargeIdB],//负责人范围
                assessResult: "", //评估结果
                tableData: tableData,//字表_个人评估
                //个人评估表
                //evaluationPointRef: "",//评估要点参考
                //AssignmentScore: "",//赋值分数
                //SelfScore:"",//自评分数
                selfEvaluation:"",// "自我评价",
                nextStepImprovementPlan: "",// "下一步提升计划",
                //领导评估
                assessScore: "",//"评估分数",
                overallEvaluation:"",// "总体评价",
                advantage: "",//"优势",
                itemImproved: "",// "待改进项",
                //个人评估表详细
                selfEvaluation_c: "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX",// "自我评价_内容"
                //履职能力评估计划会签
                ReviewOpinion: "",//评审意见

            }));

        }
    }
}
//子表_被评估人
function evaluatorList() {
    var proEvaluatorList = [];
    for (var i = 0; i < 4; i++) {
        var CourseList = {};
        CourseList.department = randomValue('n52');  //部门
        CourseList.evaluator = Mock.Random.cname();  //被评估人
        CourseList.post = randomValue('postname');  //岗位
        CourseList.straightLine = Mock.Random.cname();  //直线上级
        CourseList.remarks = randomValue('56');  //备注
        
        proEvaluatorList.push(CourseList);
    }
    return proEvaluatorList;
}

// 个人安全行动计划管理
var $PersonSafePlanManagement = {
    DealUrl: function (vueApp, url, type, param) {
        switch (url) {
            ////删除
            case '/api/PersonSafePlanManagement/DeleteMuti':
                Mock.mock(host + url, type, function (options) {
                    var delIDs = options.body;
                    var temp = [];
                    for (var i = 0; i < $PersonSafePlanManagement.Arrays.length; i++) {
                        temp.push($PersonSafePlanManagement.Arrays[i]);
                    }
                    for (var i = 0; i < temp.length; i++) {
                        if (delIDs.includes(temp[i].id)) {
                            $PersonSafePlanManagement.Arrays.splice(temp[i], 1);
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //获取List数据
            case '/api/PersonSafePlanManagement/GetList':
                Mock.mock(host + url, type,
                    function (options) {
                        if ($PersonSafePlanManagement.Arrays.length == 0) {
                            $PersonSafePlanManagement.InitArray();
                        }
                        var p = JSON.parse(options.body);
                        //查询条件 写自己的查询条件 
                        var activeName = p.model.activeName;
                        var dutyName = p.model.dutyName;
                        //分页条件
                        var offset = p.offset;
                        var limit = p.limit;
                        //查询条件 按自己实际的去过滤
                        var limitArrays2 = [];
                        for (var i = 0; i < $PersonSafePlanManagement.Arrays.length; i++) {
                            var PersonSafePlanManagement = $PersonSafePlanManagement.Arrays[i];
                            if (activeName && PersonSafePlanManagement.activeName.indexOf(activeName) == -1)
                                continue;
                            if (dutyName && PersonSafePlanManagement.dutyName.indexOf(dutyName) == -1)
                                continue;
                            limitArrays2.push(PersonSafePlanManagement);
                        }
                        var limitArrays = [];
                        for (var i = 0; i < limitArrays2.length; i++) {
                            if (i < offset + limit && i >= offset) {
                                limitArrays.push(limitArrays2[i]);
                            }
                        }
                        return {
                            result: "Success",
                            message: null,
                            data: {
                                pageData: limitArrays,
                                rowCount: limitArrays2.length
                            }
                        };
                    });
                break;
                //获取Input数据
            case '/api/PersonSafePlanManagement/get':
                Mock.mock(host + url + '?' + param, type, function (options) {
                    var myArrays = parent.$PersonSafePlanManagement.Arrays;
                    myarray = {};
                    for (var i = 0; i < myArrays.length; i++) {
                        if (myArrays[i].id == vueApp.id) {
                            myarray = myArrays[i];
                            break;
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: myarray
                    };
                });
                break;
                //提交
            case '/api/PersonSafePlanManagement/Save':
                Mock.mock(host + url, type, function (options) {
                    var thisentity = JSON.parse(options.body);
                    var thisArrays = parent.$PersonSafePlanManagement.Arrays;
                    var cz = true;
                    for (var i = 0; i < thisArrays.length; i++) {
                        //按自己实际的去修改内容
                        if (thisArrays[i].id == thisentity.id) {
                            thisArrays[i].activeName = thisentity.activeName;
                            thisArrays[i].planMain = thisentity.planMain;
                            thisArrays[i].frequency = thisentity.frequency;
                            thisArrays[i].planDate = thisentity.planDate;
                            thisArrays[i].completion = thisentity.completion;
                            thisArrays[i].examination = thisentity.examination;
                            thisArrays[i].completeDate = thisentity.completeDate;
                            thisArrays[i].completeMine = thisentity.completeMine;
                            thisArrays[i].attachment = thisentity.attachment;
                            thisArrays[i].remarks = thisentity.remarks;
                            cz = false;
                            break;
                        }
                    }
                    if (cz) {
                        //Input 页面需要 去操作List页面的数组 parent
                        //按自己实际的去添加内容
                        parent.$PersonSafePlanManagement.Arrays.push({
                            id: thisentity.id,
                            activeName: thisentity.activeName,
                            planMain: thisentity.planMain,
                            frequency: thisentity.frequency,
                            planDate: thisentity.planDate,
                            completion: thisentity.completion,
                            examination: thisentity.examination,
                            completeDate: thisentity.completeDate,
                            completeMine: thisentity.completeMine,
                            attachment: thisentity.attachment,
                            remarks: thisentity.remarks,
                        });
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
        }
    },
    Arrays: [],
    InitArray: function () {
        for (var i = 0; i < 20; i++) {
            //注意  随机数据初始都是随机姓名，需要自己手动调整
            $PersonSafePlanManagement.Arrays.push(Mock.mock({
                id: Mock.Random.id(), //必须有
                activeName: randomValue('22'),
                planMain: randomValue('19'),
                frequency: randomValue('n56'), //频率
                planDate: Mock.Random.date(),
                completion: randomValue('n54'),
                examination: randomValue('n57'),
                completeDate: Mock.Random.date(),
                completeMine: randomValue('19'),
                attachment: randomValue('n58'),
                remarks: Mock.mock('@county(true)'),
                dutyName: Mock.Random.cname(),
            }));

        }
    }
}


// 行为安全观察与沟通结果统计表
var $BehaviorSafetyObservation = {
    DealUrl: function (vueApp, url, type, param) {
        switch (url) {
            ////删除
            case '/api/BehaviorSafetyObservation/DeleteMuti':
                Mock.mock(host + url, type, function (options) {
                    var delIDs = options.body;
                    var temp = [];
                    for (var i = 0; i < $BehaviorSafetyObservation.Arrays.length; i++) {
                        temp.push($BehaviorSafetyObservation.Arrays[i]);
                    }
                    for (var i = 0; i < temp.length; i++) {
                        if (delIDs.includes(temp[i].id)) {
                            $BehaviorSafetyObservation.Arrays.splice(temp[i], 1);
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //获取List数据
            case '/api/BehaviorSafetyObservation/GetList':
                Mock.mock(host + url, type,
                    function (options) {
                        if ($BehaviorSafetyObservation.Arrays.length == 0) {
                            $BehaviorSafetyObservation.InitArray();
                        }
                        var p = JSON.parse(options.body);
                        //查询条件 写自己的查询条件 
                        var name = p.model.name;
                        var ObservationtimeStart = p.model.ObservationtimeStart;
                        var ObservationtimeEnd = p.model.ObservationtimeEnd;
                        //分页条件
                        var offset = p.offset;
                        var limit = p.limit;
                        //查询条件 按自己实际的去过滤
                        var limitArrays2 = [];
                        for (var i = 0; i < $BehaviorSafetyObservation.Arrays.length; i++) {
                            var user = $BehaviorSafetyObservation.Arrays[i];
                            if (name && user.name.indexOf(name) == -1)
                                continue;
                            if (ObservationtimeStart && ObservationtimeStart >= user.data)
                                continue;
                            if (ObservationtimeEnd && ObservationtimeEnd <= user.data)
                                continue;
                            limitArrays2.push(user);
                        }
                        var limitArrays = [];
                        for (var i = 0; i < limitArrays2.length; i++) {
                            if (i < offset + limit && i >= offset) {
                                limitArrays.push(limitArrays2[i]);
                            }
                        }
                        return {
                            result: "Success",
                            message: null,
                            data: {
                                pageData: limitArrays,
                                rowCount: limitArrays2.length
                            }
                        };
                    });
                break;
                //获取Input数据
            case '/api/BehaviorSafetyObservation/get':
                Mock.mock(host + url + '?' + param, type, function (options) {
                    var myArrays = parent.$BehaviorSafetyObservation.Arrays;
                    myarray = {};
                    for (var i = 0; i < myArrays.length; i++) {
                        if (myArrays[i].id == vueApp.id) {
                            myarray = myArrays[i];
                            break;
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: myarray
                    };
                });
                break;
                //提交
            case '/api/BehaviorSafetyObservation/Save':
                Mock.mock(host + url, type, function (options) {
                    var thisentity = JSON.parse(options.body);
                    var thisArrays = parent.$BehaviorSafetyObservation.Arrays;
                    var cz = true;
                    for (var i = 0; i < thisArrays.length; i++) {
                        //按自己实际的去修改内容
                        if (thisArrays[i].id == thisentity.id) {
                            thisArrays[i].data = thisentity.data;
                            thisArrays[i].Flights = thisentity.Flights;
                            thisArrays[i].Observer = thisentity.Observer;
                            thisArrays[i].Classification = thisentity.Classification;
                            thisArrays[i].Personnelresponse = thisentity.Personnelresponse;
                            thisArrays[i].Locationofpersonnel = thisentity.Locationofpersonnel;
                            thisArrays[i].protectiveequipment = thisentity.protectiveequipment;
                            thisArrays[i].Toolsandequipment = thisentity.Toolsandequipment;
                            thisArrays[i].program = thisentity.program;
                            thisArrays[i].StandardofOrder = thisentity.StandardofOrder;
                            cz = false;
                            break;
                        }
                    }
                    if (cz) {
                        //Input 页面需要 去操作List页面的数组 parent
                        //按自己实际的去添加内容
                        parent.$BehaviorSafetyObservation.Arrays.push({
                            id: thisentity.id,
                            data: thisentity.data,
                            Flights: thisentity.Flights,
                            Observer: thisentity.Observer,
                            Classification: thisentity.Classification,
                            Personnelresponse: thisentity.Personnelresponse,
                            Locationofpersonnel: thisentity.Locationofpersonnel,
                            protectiveequipment: thisentity.protectiveequipment,
                            Toolsandequipment: thisentity.Toolsandequipment,
                            program: thisentity.program,
                            StandardofOrder: thisentity.StandardofOrder,
                        });
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
        }
    },
    Arrays: [],
    InitArray: function () {
        for (var i = 0; i < 20; i++) {
            //注意  随机数据初始都是随机姓名，需要自己手动调整
            $BehaviorSafetyObservation.Arrays.push(Mock.mock({
                id: Mock.Random.id(), //必须有
                data: Mock.Random.date(), //履职职责落实情况名称
                Flights: randomValue('n51'), //履职职责落实情况内容
                Observer: Mock.Random.cname(), //落实情况
                Classification: randomValue('n66'), //分类
                Personnelresponse: randomValue('n55'), //评价
                Locationofpersonnel: randomValue('07'), //mock定义的日期
                protectiveequipment: randomValue('06'), //
                Toolsandequipment: randomValue('06'), //
                program: randomValue('17'), //
                StandardofOrder: randomValue('n55'), //               
                // 'score|70-100': 1,
                score: Mock.Random.string('number', 2),
                name: Mock.Random.cname(),
                remarks: Mock.mock('@county(true)'),
                unsafebehavior: randomValue('17'), //
            }));

        }
    }
}

//分类按部门进行统计
var $StatisticsbyDepartmentList = {
    DealUrl: function (vueApp, url, type, param) {
        switch (url) {
            ////删除
            case '/api/StatisticsbyDepartmentList/DeleteMuti':
                Mock.mock(host + url, type, function (options) {
                    var delIDs = options.body;
                    var temp = [];
                    for (var i = 0; i < $StatisticsbyDepartmentList.Arrays.length; i++) {
                        temp.push($StatisticsbyDepartmentList.Arrays[i]);
                    }
                    for (var i = 0; i < temp.length; i++) {
                        if (delIDs.includes(temp[i].id)) {
                            $StatisticsbyDepartmentList.Arrays.splice(temp[i], 1);
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //获取List数据
            case '/api/StatisticsbyDepartmentList/GetList':
                Mock.mock(host + url, type,
                    function (options) {
                        if ($StatisticsbyDepartmentList.Arrays.length == 0) {
                            $StatisticsbyDepartmentList.InitArray();
                        }
                        var p = JSON.parse(options.body);
                        //查询条件 写自己的查询条件 
                        var name = p.model.name;
                        var StatisticalDateStart = p.model.StatisticalDateStart;
                        var StatisticalDateEnd = p.model.StatisticalDateEnd;
                        //分页条件
                        var offset = p.offset;
                        var limit = p.limit;
                        //查询条件 按自己实际的去过滤
                        var limitArrays2 = [];
                        for (var i = 0; i < $StatisticsbyDepartmentList.Arrays.length; i++) {
                            var user = $StatisticsbyDepartmentList.Arrays[i];
                            if (name && user.name.indexOf(name) == -1)
                                continue;
                            if (StatisticalDateStart && StatisticalDateStart >= user.StatisticalDate)
                                continue;
                            if (StatisticalDateEnd && StatisticalDateEnd <= user.StatisticalDate)
                                continue;
                            limitArrays2.push(user);
                        }
                        var limitArrays = [];
                        for (var i = 0; i < limitArrays2.length; i++) {
                            if (i < offset + limit && i >= offset) {
                                limitArrays.push(limitArrays2[i]);
                            }
                        }
                        return {
                            result: "Success",
                            message: null,
                            data: {
                                pageData: limitArrays,
                                rowCount: limitArrays2.length
                            }
                        };
                    });
                break;
                //获取Input数据
            case '/api/StatisticsbyDepartmentList/get':
                Mock.mock(host + url + '?' + param, type, function (options) {
                    var myArrays = parent.$StatisticsbyDepartmentList.Arrays;
                    myarray = {};
                    for (var i = 0; i < myArrays.length; i++) {
                        if (myArrays[i].id == vueApp.id) {
                            myarray = myArrays[i];
                            break;
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: myarray
                    };
                });
                break;
                //提交
            case '/api/StatisticsbyDepartmentList/Save':
                Mock.mock(host + url, type, function (options) {
                    var thisentity = JSON.parse(options.body);
                    var thisArrays = parent.$StatisticsbyDepartmentList.Arrays;
                    var cz = true;
                    for (var i = 0; i < thisArrays.length; i++) {
                        //按自己实际的去修改内容
                        if (thisArrays[i].id == thisentity.id) {
                            thisArrays[i].riqi = thisentity.riqi;

                            break;
                        }
                    }
                    if (cz) {
                        //Input 页面需要 去操作List页面的数组 parent
                        //按自己实际的去添加内容
                        parent.$StatisticsbyDepartmentList.Arrays.push({
                            id: thisentity.id,
                            riqi: thisentity.riqi,

                        });
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
        }
    },
    Arrays: [],
    InitArray: function () {
        for (var i = 0; i < 20; i++) {
            //注意  随机数据初始都是随机姓名，需要自己手动调整
            $StatisticsbyDepartmentList.Arrays.push(Mock.mock({
                id: Mock.Random.id(), //必须有
                riqi: Mock.Random.date(), //履职职责落实情况名称

                // 'score|70-100': 1,
                score: Mock.Random.string('number', 2),
                name: Mock.Random.cname(),
                remarks: Mock.mock('@county(true)'),
                StatisticalDate: Mock.Random.date(),
                department: randomValue('15'), //部门
            }));

        }
    }
}
//hse行动计划跟进表
var $HSEActionPlanFollowupTable = {
    DealUrl: function (vueApp, url, type, param) {
        switch (url) {
            ////删除
            case '/api/HSEActionPlanFollowupTable/DeleteMuti':
                Mock.mock(host + url, type, function (options) {
                    var delIDs = options.body;
                    var temp = [];
                    for (var i = 0; i < $HSEActionPlanFollowupTable.Arrays.length; i++) {
                        temp.push($HSEActionPlanFollowupTable.Arrays[i]);
                    }
                    for (var i = 0; i < temp.length; i++) {
                        if (delIDs.includes(temp[i].id)) {
                            $HSEActionPlanFollowupTable.Arrays.splice(temp[i], 1);
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //获取List数据
            case '/api/HSEActionPlanFollowupTable/GetList':
                Mock.mock(host + url, type,
                    function (options) {
                        if ($HSEActionPlanFollowupTable.Arrays.length == 0) {
                            $HSEActionPlanFollowupTable.InitArray();
                        }
                        var p = JSON.parse(options.body);
                        //查询条件 写自己的查询条件 
                        var Sourcesofactionplans = p.model.Sourcesofactionplans;
                        var Specificcontentofactionplan = p.model.Specificcontentofactionplan;
                        var Plannedcompletiondate = p.model.Plannedcompletiondate;
                        var Personliable = p.model.Personliable;
                        var Actualcompletiontime = p.model.Actualcompletiontime;
                        var Completionstatus = p.model.Completionstatus;
                        var Briefdescriptionofcompletion = p.model.Briefdescriptionofcompletion;
                        var Remarks = p.model.Remarks;
                        var PlannedcompletiondateStart = p.model.PlannedcompletiondateStart;
                        var PlannedcompletiondateEnd = p.model.PlannedcompletiondateEnd;
                        var ActualcompletiontimeStart = p.model.ActualcompletiontimeStart;
                        var ActualcompletiontimeEnd = p.model.ActualcompletiontimeEnd;
                        //分页条件
                        var offset = p.offset;
                        var limit = p.limit;
                        //查询条件 按自己实际的去过滤
                        var limitArrays2 = [];
                        for (var i = 0; i < $HSEActionPlanFollowupTable.Arrays.length; i++) {
                            var HSEActionPlanFollowupTable = $HSEActionPlanFollowupTable.Arrays[i];
                            if (Sourcesofactionplans && HSEActionPlanFollowupTable.Sourcesofactionplans.indexOf(Sourcesofactionplans) == -1)
                                continue;
                            if (Specificcontentofactionplan && HSEActionPlanFollowupTable.Specificcontentofactionplan.indexOf(Specificcontentofactionplan) == -1)
                                continue;
                            if (Plannedcompletiondate && HSEActionPlanFollowupTable.Plannedcompletiondate.indexOf(Plannedcompletiondate) == -1)
                                continue;
                            if (Personliable && HSEActionPlanFollowupTable.Personliable.indexOf(Personliable) == -1)
                                continue;
                            if (Actualcompletiontime && HSEActionPlanFollowupTable.Actualcompletiontime.indexOf(Actualcompletiontime) == -1)
                                continue;
                            if (Completionstatus && HSEActionPlanFollowupTable.Completionstatus.indexOf(Completionstatus) == -1)
                                continue;
                            if (Briefdescriptionofcompletion && HSEActionPlanFollowupTable.Briefdescriptionofcompletion.indexOf(Briefdescriptionofcompletion) == -1)
                                continue;
                            if (Remarks && HSEActionPlanFollowupTable.Remarks.indexOf(Remarks) == -1)
                                continue;
                            if (PlannedcompletiondateStart && PlannedcompletiondateStart >= HSEActionPlanFollowupTable.Plannedcompletiondate)
                                continue;
                            if (PlannedcompletiondateEnd && PlannedcompletiondateEnd <= HSEActionPlanFollowupTable.Plannedcompletiondate)
                                continue;
                            if (ActualcompletiontimeStart && ActualcompletiontimeStart >= HSEActionPlanFollowupTable.Actualcompletiontime)
                                continue;
                            if (ActualcompletiontimeEnd && ActualcompletiontimeEnd <= HSEActionPlanFollowupTable.Actualcompletiontime)
                                continue;
                            limitArrays2.push(HSEActionPlanFollowupTable);
                        }
                        var limitArrays = [];
                        for (var i = 0; i < limitArrays2.length; i++) {
                            if (i < offset + limit && i >= offset) {
                                limitArrays.push(limitArrays2[i]);
                            }
                        }
                        return {
                            result: "Success",
                            message: null,
                            data: {
                                pageData: limitArrays,
                                rowCount: limitArrays2.length
                            }
                        };
                    });
                break;
                //获取Input数据
            case '/api/HSEActionPlanFollowupTable/get':
                Mock.mock(host + url + '?' + param, type, function (options) {
                    var myArrays = parent.$HSEActionPlanFollowupTable.Arrays;
                    myarray = {};
                    for (var i = 0; i < myArrays.length; i++) {
                        if (myArrays[i].id == vueApp.id) {
                            myarray = myArrays[i];
                            break;
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: myarray
                    };
                });
                break;
                //提交
            case '/api/HSEActionPlanFollowupTable/Save':
                Mock.mock(host + url, type, function (options) {
                    var thisentity = JSON.parse(options.body);
                    var thisArrays = parent.$HSEActionPlanFollowupTable.Arrays;
                    var cz = true;
                    for (var i = 0; i < thisArrays.length; i++) {
                        //按自己实际的去修改内容
                        if (thisArrays[i].id == thisentity.id) {
                            thisArrays[i].Sourcesofactionplans = thisentity.Sourcesofactionplans;
                            thisArrays[i].Serialnumber = thisentity.Serialnumber;
                            thisArrays[i].Specificcontentofactionplan = thisentity.Specificcontentofactionplan;
                            thisArrays[i].Plannedcompletiondate = thisentity.Plannedcompletiondate;
                            thisArrays[i].Briefdescriptionofcompletion = thisentity.Briefdescriptionofcompletion;
                            thisArrays[i].Personliable = thisentity.Personliable;
                            thisArrays[i].Actualcompletiontime = thisentity.Actualcompletiontime;
                            thisArrays[i].Completionstatus = thisentity.Completionstatus;
                            thisArrays[i].Remarks = thisentity.Remarks;

                            break;
                        }
                    }
                    if (cz) {
                        //Input 页面需要 去操作List页面的数组 parent
                        //按自己实际的去添加内容
                        parent.$HSEActionPlanFollowupTable.Arrays.push({
                            id: thisentity.id,
                            Sourcesofactionplans: thisentity.Sourcesofactionplans,
                            Serialnumber: thisentity.Serialnumber,
                            Specificcontentofactionplan: thisentity.Specificcontentofactionplan,
                            Plannedcompletiondate: thisentity.Plannedcompletiondate,
                            Briefdescriptionofcompletion: thisentity.Briefdescriptionofcompletion,
                            Personliable: thisentity.Personliable,
                            Actualcompletiontime: thisentity.Actualcompletiontime,
                            Completionstatus: thisentity.Completionstatus,
                            Remarks: thisentity.Remarks,

                        });
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
        }
    },
    Arrays: [],
    InitArray: function () {
        for (var i = 0; i < 20; i++) {
            //注意  随机数据初始都是随机姓名，需要自己手动调整
            $HSEActionPlanFollowupTable.Arrays.push(Mock.mock({
                id: Mock.Random.id(), //必须有
                Sourcesofactionplans: randomValue('04'), //
                Serialnumber: Mock.Random.string('number', 2), //
                Specificcontentofactionplan: randomValue('04'), //
                Plannedcompletiondate: Mock.Random.date(), //
                Briefdescriptionofcompletion: randomValue('17'), //
                Personliable: randomValue('02'), //
                Actualcompletiontime: Mock.Random.date(), //
                Completionstatus: randomValue('n54'), //
                Remarks: randomValue('43'), //

            }));

        }
    }
}
//======Date:2019.07.30,By:Wanglr======//
//岗位安全考核模板设置
var $PostSafeAssessmentTemplateList = {
    DealUrl: function (vueApp, url, type, param) {
        switch (url) {
            ////删除
            case '/api/PostSafeAssessmentTemplate/DeleteMuti':
                Mock.mock(host + url, type, function (options) {

                    var delIDs = options.body;
                    var temp = [];
                    delIDs = delIDs.indexOf('"') > 0 ? delIDs.replace('"', '') : delIDs;

                    for (var i = 0; i < parent.$PostSafeAssessmentTemplateList.Arrays.length; i++) {
                        temp.push(parent.$PostSafeAssessmentTemplateList.Arrays[i]);
                    }
                    for (var i = 0; i < temp.length; i++) {
                        if (delIDs.includes(temp[i].id)) {
                            parent.$PostSafeAssessmentTemplateList.Arrays.splice(temp[i], 1);

                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //获取List数据
            case '/api/PostSafeAssessmentTemplate/GetList':
                Mock.mock(host + url, type,
                    function (options) {
                        if ($PostSafeAssessmentTemplateList.Arrays.length == 0) {
                            $PostSafeAssessmentTemplateList.InitArray();
                        }
                        var p = JSON.parse(options.body);
                        //查询条件 写自己的查询条件 
                        var post = p.model.post;
                        //分页条件
                        var offset = p.offset;
                        var limit = p.limit;
                        //查询条件 按自己实际的去过滤
                        var limitArrays2 = [];
                        for (var i = 0; i < $PostSafeAssessmentTemplateList.Arrays.length; i++) {
                            var obj = $PostSafeAssessmentTemplateList.Arrays[i];
                            if (post && obj.post.indexOf(post) == -1)
                                continue;
                            limitArrays2.push(obj);
                        }
                        var limitArrays = [];
                        for (var i = 0; i < limitArrays2.length; i++) {
                            if (i < offset + limit && i >= offset) {
                                limitArrays.push(limitArrays2[i]);
                            }
                        }
                        return {
                            result: "Success",
                            message: null,
                            data: {
                                pageData: limitArrays,
                                rowCount: limitArrays2.length
                            }
                        };
                    });
                break;
                //获取Input数据
            case '/api/PostSafeAssessmentTemplate/get':
                Mock.mock(host + url + '?' + param, type, function (options) {
                    var oldArrays = parent.$PostSafeAssessmentTemplateList.Arrays;
                    var myArrays = [];
                    $.extend(true, myArrays, oldArrays);
                    myarray = {};
                    var result = [];
                    for (var i = 0; i < myArrays.length; i++) {
                        if (myArrays[i].post == vueApp.id) {
                            result.push(myArrays[i]);
                        }
                    }
                    myarray.tableData = result;
                    return {
                        result: "Success",
                        message: null,
                        data: myarray
                    };
                });
                break;
                //提交
            case '/api/PostSafeAssessmentTemplate/Save':
                Mock.mock(host + url, type, function (options) {
                    var thisentity = JSON.parse(options.body);
                    var thisArrays = parent.$PostSafeAssessmentTemplateList.Arrays;
                    var delIndex = [];
                    for (var i = 0; i < thisArrays.length; i++) {
                        if (thisArrays[i].post == thisentity.post) {
                            delIndex.push(i);
                        }
                    }
                    console.log('delIndex', delIndex)
                    for (var i = delIndex.length - 1; i >= 0; i--) {
                        console.log(delIndex[i])
                        parent.$PostSafeAssessmentTemplateList.Arrays.splice(delIndex[i], 1);
                    }
                    for (var i = 0; i < thisentity.tableData.length; i++) {
                        parent.$PostSafeAssessmentTemplateList.Arrays.push({
                            id: thisentity.tableData[i].id, //id
                            postSafeProductionContent: thisentity.tableData[i].postSafeProductionContent, //岗位安全生产责任内容
                            assessmentContent: thisentity.tableData[i].assessmentContent, //考核内容
                            weightScore: thisentity.tableData[i].weightScore, //权重分
                            post: thisentity.tableData[i].post, //岗位
                        });
                    }

                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
        }
    },
    Arrays: [],
    InitArray: function () {
        for (var i = 0; i < 20; i++) {
            $PostSafeAssessmentTemplateList.Arrays.push(Mock.mock({
                id: Mock.Random.id(), //id
                postSafeProductionContent: Mock.mock('@cparagraph(1, 3)'), //岗位安全生产责任内容
                assessmentContent: Mock.mock('@cparagraph(1, 3)'), //考核内容
                weightScore: Mock.Random.string('number', 2), //权重分
                post: randomKey('postname'), //岗位
                //assessmentSubject: '2019年XXX考核',//考核主题
                //year: '2019',//年份
                //postSafeProductionScope: Mock.mock('@cparagraph(1, 3)'),//岗位安全生产责任范围
                //effectAndDescription: Mock.mock('@cparagraph(1, 3)'),//工作效果和评估描述
                //score: Mock.Random.string('number', 2),//评分

            }));

        }
    }
}
//岗位安全职责考核管理
var $PostSafeResponsibilityExamineManager = {
    DealUrl: function (vueApp, url, type, param) {
        switch (url) {
            ////删除
            case '/api/PostSafeResponsibilityExamineManager/DeleteMuti':
                Mock.mock(host + url, type, function (options) {
                    var delIDs = options.body;
                    var temp = [];
                    for (var i = 0; i < $PostSafeResponsibilityExamineManager.Arrays.length; i++) {
                        temp.push($PostSafeResponsibilityExamineManager.Arrays[i]);
                    }
                    for (var i = 0; i < temp.length; i++) {
                        if (delIDs.includes(temp[i].id)) {
                            $PostSafeResponsibilityExamineManager.Arrays.splice(temp[i], 1);
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
                //获取List数据
            case '/api/PostSafeResponsibilityExamineManager/GetList':
                Mock.mock(host + url, type,
                    function (options) {
                        if ($PostSafeResponsibilityExamineManager.Arrays.length == 0) {
                            $PostSafeResponsibilityExamineManager.InitArray();
                        }
                        var p = JSON.parse(options.body);
                        //查询条件 写自己的查询条件 
                        var assessmentSubject = p.model.assessmentSubject;
                        var assessmentYear = p.model.assessmentYear;

                        console.log('p', p.model)
                        console.log('assessmentYear', assessmentYear)
                        var post = p.model.post;
                        //分页条件
                        var offset = p.offset;
                        var limit = p.limit;
                        //查询条件 按自己实际的去过滤
                        var limitArrays2 = [];
                        for (var i = 0; i < $PostSafeResponsibilityExamineManager.Arrays.length; i++) {
                            var obj = $PostSafeResponsibilityExamineManager.Arrays[i];
                            if (assessmentSubject && obj.assessmentSubject.indexOf(assessmentSubject) == -1)
                                continue;
                            if (assessmentYear && obj.assessmentYear.indexOf(assessmentYear) == -1)
                                continue;
                            if (post && obj.post.indexOf(post) == -1)
                                continue;
                            limitArrays2.push(obj);
                        }
                        var limitArrays = [];
                        for (var i = 0; i < limitArrays2.length; i++) {
                            if (i < offset + limit && i >= offset) {
                                limitArrays.push(limitArrays2[i]);
                            }
                        }
                        return {
                            result: "Success",
                            message: null,
                            data: {
                                pageData: limitArrays,
                                rowCount: limitArrays2.length
                            }
                        };
                    });
                break;
                //获取Input数据
            case '/api/PostSafeResponsibilityExamineManager/get':
                Mock.mock(host + url + '?' + param, type, function (options) {
                    var myArrays = parent.$PostSafeResponsibilityExamineManager.Arrays;
                    myarray = {};
                    for (var i = 0; i < myArrays.length; i++) {
                        if (myArrays[i].id == vueApp.id) {
                            myarray = myArrays[i];
                            break;
                        }
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: myarray
                    };
                });
                break;
                //提交
            case '/api/PostSafeResponsibilityExamineManager/Save':
                Mock.mock(host + url, type, function (options) {
                    var thisentity = JSON.parse(options.body);
                    var thisArrays = parent.$PostSafeResponsibilityExamineManager.Arrays;



                    console.log('thisentity', thisentity)
                    var cz = true;
                    for (var i = 0; i < thisArrays.length; i++) {
                        if (thisArrays[i].id == thisentity.id) {
                            thisArrays[i].assessmentSubject = thisentity.assessmentSubject;
                            thisArrays[i].assessmentYear = thisentity.assessmentYear;
                            thisArrays[i].post = thisentity.post;
                            thisArrays[i].assessmentScore = thisentity.assessmentScore;
                            thisArrays[i].postPerson = thisentity.postPerson;
                            thisArrays[i].writeTime = thisentity.writeTime;
                            thisArrays[i].superiorLeaders = thisentity.superiorLeaders;
                            thisArrays[i].approvalTime = thisentity.approvalTime;
                            thisArrays[i].status = thisentity.status;
                            thisArrays[i].postSafeProductionScope = thisentity.postSafeProductionScope;
                            thisArrays[i].tableData = thisentity.tableData;

                            cz = false;

                            break;
                        }
                    }
                    if (cz) {
                        parent.$PostSafeResponsibilityExamineManager.Arrays.unshift({
                            id: Mock.Random.id(),
                            assessmentSubject: thisentity.assessmentSubject, //考核主题
                            assessmentYear: thisentity.assessmentYear, //考核年份
                            post: thisentity.post, //岗位
                            assessmentScore: thisentity.assessmentScore, //考核得分
                            postPerson: thisentity.postPerson, //岗位人员
                            writeTime: thisentity.writeTime, //填写时间
                            superiorLeaders: thisentity.superiorLeaders, //上级领导
                            approvalTime: thisentity.approvalTime, //审批时间
                            status: thisentity.status, //状态 保存 提交
                            postSafeProductionScope: thisentity.postSafeProductionScope, //岗位安全生产责任范围
                            tableData: thisentity.tableData,

                        });
                    }
                    return {
                        result: "Success",
                        message: null,
                        data: null
                    };
                });
                break;
        }
    },
    Arrays: [],
    InitArray: function () {
        for (var i = 0; i < 20; i++) {
            var PersonInChargePidA = randomTreeNode(UsersTree, '0', true);
            var PersonInChargeIdA = randomTreeNode(UsersTree, PersonInChargePidA);
            var tableData = [];
            for (var j = 0; j < 3; j++) {
                tableData.push({
                    postSafeProductionContent: Mock.mock('@cparagraph(1, 3)'), //岗位安全生产责任内容
                    assessmentContent: Mock.mock('@cparagraph(1, 3)'), //考核内容
                    weightScore: Mock.Random.string('number', 2), //权重分
                    effectAndDescription: Mock.mock('@cparagraph(1, 3)'), //评估描述
                    score: Mock.Random.string('number', 2), //评分
                })
            }
            $PostSafeResponsibilityExamineManager.Arrays.push(Mock.mock({
                id: Mock.Random.id(),
                assessmentSubject: Mock.mock('@cparagraph(1, 3)'), //考核主题
                assessmentYear: '2019', //考核年份
                post: randomKey('postname'), //岗位
                assessmentScore: Mock.Random.string('number', 2), //考核得分
                postPerson: PersonInChargeIdA, //岗位人员
                writeTime: Mock.Random.date(), //填写时间
                superiorLeaders: Mock.Random.cname(), //上级领导
                approvalTime: Mock.Random.date(), //审批时间
                status: '保存', //状态 保存 提交
                postSafeProductionScope: Mock.mock('@cparagraph(1, 3)'), //岗位安全生产责任范围
                tableData: tableData,




            }));

        }
    }
}




////生成treeNode随机数,如果b为true则获取父级节点，否则为最底级节点
//var pid = randomTreeNode(RisksTree, '0', true); 获取父id为0（顶级节点），数据集为RisksTree中的节点，并随机返回一条
//var cid = randomTreeNode(RisksTree, pid);获取父id为pid，数据集为RisksTree中的最底级节点，并随机返回一条
//var id  = randomTreeNode(RisksTree);获取数据集为RisksTree中的最底级节点，并随机返回一条
function randomTreeNode(tree, pid, b) {
    var result = '';
    var tempArray = [];
    if (!b) {
        var idArray = [];
        var pidArray = [];
        tree.forEach(function (v, i) {
            if (pid) {
                if (pid == v.pid) {
                    idArray.push(v.id);
                    pidArray.push(v.pid);
                }
            } else {
                idArray.push(v.id);
                pidArray.push(v.pid);
            }
        })
        tempArray = idArray.filter(function (v) {
            return pidArray.indexOf(v) === -1
        });
        result = tempArray[Math.floor(Math.random() * tempArray.length)] + '';
    } else {
        tree.forEach(function (v, i) {
            if (v.pid + '' == '0') {
                tempArray.push(v.id);
            }
        })
        result = tempArray[Math.floor(Math.random() * tempArray.length)] + '';
    }
    return result;
}
//根据tree数据中的id获取对应的name值
function getTreeValue(tree, id) {
    var value = '';
    tree.forEach(function (v, i) {
        if (v.id + '' == id + '') {
            value = v.name;
            return;
        }
    })
    return value;
}
var UsersTree = [{
        "id": 100,
        "pid": 0,
        "name": "总经理"
    },
    {
        "id": 200,
        "pid": 0,
        "name": "生产部"
    },
    {
        "id": 300,
        "pid": 0,
        "name": "技术科"
    },
    {
        "id": 400,
        "pid": 0,
        "name": "工程设备科"
    },
    {
        "id": 100001,
        "pid": 100,
        "name": "张三"
    },
    {
        "id": 100002,
        "pid": 100,
        "name": "李四"
    },
    {
        "id": 200001,
        "pid": 200,
        "name": "胡伟"
    },
    {
        "id": 200002,
        "pid": 200,
        "name": "胡博"
    },
    {
        "id": 300001,
        "pid": 300,
        "name": "李师伯"
    },
    {
        "id": 300002,
        "pid": 300,
        "name": "康师傅"
    },
    {
        "id": 400001,
        "pid": 400,
        "name": "王二"
    },
]